const live = require('../models/live')
const Sequelize = require('sequelize');
const Op = Sequelize.Op;

class liveDao {
  // 创建
  static async create(v) {
    const res = await live.create(
      v
    )
    return res
  }
  // 获取所有信息
  static async findAll(v) {
    const res = await live.findAndCountAll({
      limit: v.limit,
      offset: v.offset
    })
    let result = {}
    result.data = res.rows;
    result.total = res.count;
    return result
  }
  // 获取单条信息
  static async findById(v) {
    const res = await live.findOne({
      where: {
        id: v
      },
    });
    return res
  }
  // 删除
  static async delById(v) {
    const res = await live.destroy({
      where:{
        id:v
      }
    })
    return res
  }
  // 更新数据
  static async upd(v) {
    const res = await live.update(v, {
      where: {
        id: v.id
      }
    })
    return res
  }
}

module.exports = liveDao